<?php


namespace app\model;


use app\libs\exception\BaseException;
use app\libs\exception\NotFoundException;
use app\libs\exception\ServerError;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
use think\model\concern\SoftDelete;

class BaseModel extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $hidden = ['delete_time'];

    /**
     * @throws NotFoundException
     * @throws ServerError
     */
    public function select($data = null): Collection
    {
        try {
            return parent::select($data);
        } catch (DataNotFoundException $e) {
            throw new NotFoundException();
        } catch (ModelNotFoundException | DbException $e) {
            throw new ServerError();
        }
    }

    /**
     * @throws ServerError
     * @throws NotFoundException
     */
    public function find($data = null)
    {
        try {
            return parent::find($data);
        } catch (DataNotFoundException $e) {
            throw new NotFoundException();
        } catch (ModelNotFoundException | DbException $e) {
            throw new ServerError();
        }
    }

    /**
     * @throws NotFoundException
     */
    public function isNoFound($data)
    {
        if (!$data) {
            throw new NotFoundException();
        }
    }
}